﻿@model Column
@section css{
    <style>
        .layui-form-item .layui-input {
            width: 350px;
            padding-right: 10px;
            line-height: 38px;
        }

        .layui-form-item .layui-textarea {
            width: 350px;
        }

        .layui-form-select {
            width: 350px;
        }
    </style>
}
<form class="layui-form" action="" lay-filter="column-edit">
    <div class="layuimini-container layuimini-page-anim">
        <div class="layuimini-main">
            <div class="layui-form layuimini-form">
                @if (Model.Id > 0)
                {
                    <div class="layui-form-item">
                        <label class="layui-form-label">编号</label>
                        <div class="layui-input-block">
                            <input type="text" name="id" lay-verify="id" value="@Model.Id" disabled class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label required">添加时间</label>
                        <div class="layui-input-block">
                            <input type="text" name="createTime" value="@Model.CreateTime.ToWebString()" readonly class="layui-input">
                        </div>
                    </div>
                }
                <div class="layui-form-item">
                    <label class="layui-form-label required">所属父级</label>
                    <div class="layui-input-block">
                        <select name="parentId" id="parentId" lay-verify="parentId" lay-filter="parentId">
                            <option value="0">请选择父级菜单</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label required">栏目标题</label>
                    <div class="layui-input-block">
                        <input type="text" name="title" lay-verify="required" value="@Model.Title" lay-reqtext="栏目名称不能为空" placeholder="请输入栏目名称" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">栏目副标题</label>
                    <div class="layui-input-block">
                        <input type="text" name="subTitle" value="@Model.SubTitle" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label required">英文名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="enTitle" value="@Model.EnTitle" lay-verify="required" lay-reqtext="英文名称不能为空" placeholder="请输入英文名称" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label required">关键字</label>
                    <div class="layui-input-block">
                        <input type="text" name="keyword" value="@Model.Keyword" lay-verify="required" lay-reqtext="关键字不能为空" placeholder="请输入关键字" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label required">描述信息</label>
                    <div class="layui-input-block">
                        <textarea name="summary" lay-verify="required" class="layui-textarea" placeholder="请输入描述信息">@Model.Summary</textarea>
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>
@section js{
    <script src="~/js/bind-tree.js" asp-append-version="true"></script>
    <script>

            layui.use(['form',  'common'], function () {
                var form = layui.form,
                    $ = layui.$,
                    apiUtil = layui.common;

                /**
                 * 初始化表单，要加上，不然刷新部分组件可能会不加载
                 */
                // 当前弹出层，防止ID被覆盖
                var parentIndex =  parent.layer.getFrameIndex(window.name);

                var id=@Model.Id;
                if (id > 0)
                {
                    apiUtil.BindParentColumn(@Model.ParentId);
                } else {
                    apiUtil.BindParentColumn();
                }
                form.render();
                //监听提交
                form.on('submit(saveBtn)', function (data) {
                    if (data.field.id>0) {
                        apiUtil.ajax('column/modify', data.field, "application/json", "put", function (res) {
                            if (res.statusCode == 200 && res.success == true) {
                                apiUtil.success(res.msg);
                                parent.layer.close(parentIndex);
                            } else {
                                apiUtil.error(res.msg);
                            }
                        });
                    } else {
                        apiUtil.ajax('column/add', data.field, "application/json", "post", function (res) {
                            if (res.statusCode == 200 && res.success == true) {
                                apiUtil.success(res.msg);
                                parent.layer.close(parentIndex);
                            } else {
                                apiUtil.error(res.msg);
                            }
                        });
                    }
                    return false;
                });
            });

    </script>

}
